﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

using BulletSharp;

namespace KinectGame
{
    public class MenuElementEventArgs : EventArgs
    {
        public int id;
    }

    public class MenuElement
    {
        private GameObject elementObject;
        public GameObject ElementObject
        {
            get { return elementObject; }
        }
        
        private HingeConstraint elementConstraint;
        public HingeConstraint ElementConstraint
        {
            get { return elementConstraint; }
        }
        
        private RigidBody elementRigidBody;
        public RigidBody ElementRigidBody
        {
            get { return elementRigidBody; }
        }
        
        private int id;
        public int Id
        {
            get { return id; }
        }

        public event EventHandler OnChoice, OnEnter;

        public MenuElement(Model model, Vector3 scale, float rotation, float radious, float mass, int id)
        {
            Vector3 pos = Vector3.Transform(new Vector3(0,0,radious), Matrix.CreateRotationY(MathHelper.ToRadians(rotation)));

            elementObject = new GameObject(model, scale, new Vector3(0, rotation, 0), pos, mass);
            elementObject.Activate();

            elementRigidBody = elementObject.RigidBody;
            elementConstraint = new HingeConstraint(elementRigidBody, new Vector3(0, 0, -radious), Vector3.Up);

            this.id = id;
        }

        public void InvokeOnChoice()
        {
            if (OnChoice != null)
            {
                MenuElementEventArgs args = new MenuElementEventArgs();
                args.id = this.id;
                OnChoice.Invoke(this, args);
            }
        }

        public void InvokeOnEnter()
        {
            if (OnEnter != null)
            {
                MenuElementEventArgs args = new MenuElementEventArgs();
                args.id = this.id;
                OnEnter.Invoke(this, args);
            }
        }
    }
}
